﻿using System.Drawing;
using System.IO;
using RedRiver.Framework.XtraCommon.Templates;
using TianjinRedriver.Common.Shell;

namespace RedRiver.Framework.XtraCommon.FormHelper {
    public partial class TextEditForm : XtraCommonForm{
        private Image _titleImage;
        public TextEditForm() {
            InitializeComponent();
        }

        public override Image TitleImage {
            get { return _titleImage; }
        }

        public void OpenFile(string fileName){
            string filePath = Path.GetFullPath(fileName);
            if (File.Exists(filePath)) {
                using (var reader = File.OpenText(filePath)) {
                    textEdit.Text = reader.ReadToEnd();
                    _titleImage = ShellImageList.GetIcon(fileName, false).ToBitmap();
                    SubTitle = Path.GetFileName(fileName);
                }
            } else{
                throw new FileNotFoundException("文件不存在", fileName);
            }
        }
    }
}